package com.xqb.modules.controller.study;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.StdPointsRecord;
import com.xqb.modules.service.IStdPointsRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学习积分记录Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/study/points_record")
public class StdPointsRecordController extends BaseController
{
    @Autowired
    private IStdPointsRecordService stdPointsRecordService;

    /**
     * 查询学习积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('study:points_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(StdPointsRecord stdPointsRecord)
    {
        startPage();
        List<StdPointsRecord> list = stdPointsRecordService.selectStdPointsRecordList(stdPointsRecord);
        return getDataTable(list);
    }

    /**
     * 导出学习积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('study:points_record:export')")
    @Log(title = "学习积分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StdPointsRecord stdPointsRecord)
    {
        List<StdPointsRecord> list = stdPointsRecordService.selectStdPointsRecordList(stdPointsRecord);
        ExcelUtil<StdPointsRecord> util = new ExcelUtil<StdPointsRecord>(StdPointsRecord.class);
        util.exportExcel(response, list, "学习积分记录数据");
    }

    /**
     * 获取学习积分记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:points_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stdPointsRecordService.selectStdPointsRecordById(id));
    }

    /**
     * 新增学习积分记录
     */
    @PreAuthorize("@ss.hasPermi('study:points_record:add')")
    @Log(title = "学习积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StdPointsRecord stdPointsRecord)
    {
        return toAjax(stdPointsRecordService.insertStdPointsRecord(stdPointsRecord));
    }

    /**
     * 修改学习积分记录
     */
    @PreAuthorize("@ss.hasPermi('study:points_record:edit')")
    @Log(title = "学习积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StdPointsRecord stdPointsRecord)
    {
        return toAjax(stdPointsRecordService.updateStdPointsRecord(stdPointsRecord));
    }

    /**
     * 删除学习积分记录
     */
    @PreAuthorize("@ss.hasPermi('study:points_record:remove')")
    @Log(title = "学习积分记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stdPointsRecordService.deleteStdPointsRecordByIds(ids));
    }
}
